package com.rf.richfitwheel.workflow.service;

import com.rf.richfitwheel.admin.sys.vo.UserVO;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.workflow.model.WfAuthRule;
import net.sf.json.JSONObject;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import javax.script.ScriptException;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface WfProcessService {

    List<ActivityImpl> findNextUserTaskActivitys(ActivityImpl nowActivityImpl, Map<String, Object> variables);

    Set<ActivityImpl> findPrevUserTaskActivitys(ActivityImpl nowActivityImpl);

    HistoricProcessInstance getHistoricProcessInstanceById(String processInstanceId);

    HistoricProcessInstance getHistoricProcessInstanceByBusinessKey(String businessKey);

    ProcessInstance getProcessInstanceById(String processInstanceId);

    ProcessInstance getProcessInstanceByBusinessKey(String businessKey);

    /**
     * 签收任务
     *
     * @param taskId
     * @param userId
     */
    public void doClaim(String taskId, String userId) throws Exception;


    void restartByBusinessKey(String businessKey, UserVO user);

    List<Map<String, Object>> getBackTasks(String taskId);

    TaskDefinition nextTaskDefinition(ActivityImpl activityImpl, String activityId,
                                      Map<String, Object> variables, String processInstanceId);

    void doBackward(String currentTaskId, String targetTaskId, String approveMessage);

    void doForward(String currentTaskId, String targetTaskId, String approveMessage);

    void doJump(Task task, String targetTaskDefKey, String approveMessage, Map<String, Object> variables);

    void restartByCreater(String processId, UserVO user) throws Exception;

    String getApproveAdviceByTaskId(String taskId);

    List<Map<String, Object>> getHistoryTaskByProcessInstanceId(String processInstanceId);

    PageUtils queryPartakeList(String page, String limit, String dataForm, String userId, String moduleType);

    PageUtils queryCreateList(int page, int limit, JSONObject obj, String userId) throws Exception;

    void recall(Map<String, Object> params, UserVO user, UserVO system);

    void deleteProcess(String processid, String deleteReason, UserVO user);


    void deleteProcessByBusinessKey(String businessKey, String deleteReason, UserVO user);

    PageUtils queryProcessList(Map<String, Object> params, UserVO user);

    List<Map<String, Object>> getHistoryTaskByBusinessKey(String businessKey);

    Map<String, Object> getProcessVariablesByProcessInstanceId(String id);

    void recordTransfer(Task task, Map<String, Object> variables);

    ActivityImpl getFirstUserTask(String processDefinitionId);

    ActivityImpl getFirstUserTask(ProcessDefinition processdefinition);

    List<WfAuthRule> findAuthRuleByTask(Task task);

    WfAuthRule validAuthRules(Task task, Map<String, Object> variables) throws ScriptException;

    void dealWithNextTask(String processInstanceId, Map<String, Object> variables, String approveUserId) throws ScriptException;
    void dealWithNextTaskForMq(String processInstanceId, Map<String, Object> variables, String approveUserId, UserVO user) throws ScriptException;

    /**
     * 判断该节点后续是否还有授权规则
     * @param task 当前节点任务
     * @param variables 参数
     * @return true代表还有授权规则，不能结束；false代表可以结束
     */
    boolean checkAllWfAuthRuleFollow(Task task, Map<String, Object> variables) throws ScriptException;
}
